package com.shwread.android.ui.customview;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;

import com.shwread.android.qysw10000243.R;

import logic.util.ScreenUtil;


/**
 * @author xuzhijun
 * @date 2015年5月13日下午3:23:51
 */
public class WarnToast
        extends
        Toast
{
	private TextView contentTV;
	
	private Context  context;
	private String   contentString;
	private int      drawableID;
	
	public WarnToast(Context context, String contentString, int drawableID) {
		super(context);
		this.context = context;
		this.contentString = contentString;
		this.drawableID = drawableID;
		init();
	}
	
	private void init() {
		LinearLayout layout = new LinearLayout(context);
		LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		layout.setBackgroundResource(R.drawable.warn_toast_bg);
		int paddingInt = ScreenUtil.dip2px(15);
		layout.setPadding(paddingInt, paddingInt, paddingInt, paddingInt);
		layout.setLayoutParams(lp);
		contentTV = new TextView(context);
		contentTV.setText(contentString);
		contentTV.setTextSize(ScreenUtil.dip2px(8));
		contentTV.setTextColor(Color.WHITE);
		contentTV.setGravity(Gravity.CENTER);
		Drawable drawable = context.getResources().getDrawable(drawableID);
		drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
		contentTV.setCompoundDrawables(null, drawable, null, null);
		contentTV.setCompoundDrawablePadding(ScreenUtil.dip2px(10));
		contentTV.setMaxWidth(ScreenUtil.dip2px(140));
		layout.addView(contentTV);
		this.setView(layout);
		this.setDuration(Toast.LENGTH_SHORT);
		this.setGravity(Gravity.CENTER, 0, 0);
	}
}
